package com.wdh.kjs.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.wdh.kjs.R;
import com.wdh.kjs.http.Httpurl;
import com.wdh.kjs.model.JsonModel_my;
import com.wdh.kjs.util.ToastUtils;

/**
 * Created by CQH on 2016/4/28.
 */
public class ConnectUsActivity extends BaseTopActivity implements View.OnClickListener {
    private TextView content_1;
    private TextView title_1;
    private TextView title_2;
    private TextView content_2;
    private TextView title_3;
    private TextView content_3;
    private TextView title_4;
    private TextView content_4;
    private JsonModel_my jsonModel_my;
    private LinearLayout ii_title_1;
    private LinearLayout ii_title_2;
    private LinearLayout ii_title_3;
    private LinearLayout ii_title_4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.connect_us);
        initview();
        loadData();
    }

    private void loadData() {
        RequestParams params = new RequestParams();
        params.addBodyParameter("sign", "2");

        HttpUtils http = new HttpUtils();
        http.send(HttpRequest.HttpMethod.POST, Httpurl.URL_PLATFORM_INFO, params, new RequestCallBack<String>() {

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {

                Gson gson = new Gson();
                jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
//                Log.i("msg","666");
                if (jsonModel_my.success) {
                    int len = jsonModel_my.getResult().size();
                    switch (len){
                        case 0:
                            ii_title_1.setVisibility(View.GONE);
                            ii_title_2.setVisibility(View.GONE);
                            ii_title_3.setVisibility(View.GONE);
                            ii_title_4.setVisibility(View.GONE);
                            break;
                        case 1:
                            content_1.setText(Html.fromHtml(jsonModel_my.getResult().get(0).getContent()));
                            title_1.setText(Html.fromHtml(jsonModel_my.getResult().get(0).getTitle()));
                            ii_title_2.setVisibility(View.GONE);
                            ii_title_3.setVisibility(View.GONE);
                            ii_title_4.setVisibility(View.GONE);
                            break;
                        case 2:
                            content_1.setText(Html.fromHtml(jsonModel_my.getResult().get(0).getContent()));
                            title_1.setText(Html.fromHtml(jsonModel_my.getResult().get(0).getTitle()));

                            content_2.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getContent()));
                            title_2.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getTitle()));
                            ii_title_3.setVisibility(View.GONE);
                            ii_title_4.setVisibility(View.GONE);

                            break;
                        case 3:
                            content_1.setText(Html.fromHtml(jsonModel_my.getResult().get(0).getContent()));
                            title_1.setText(Html.fromHtml(jsonModel_my.getResult().get(0).getTitle()));

                            content_2.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getContent()));
                            title_2.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getTitle()));

                            content_3.setText(Html.fromHtml(jsonModel_my.getResult().get(2).getContent()));
                            title_3.setText(Html.fromHtml(jsonModel_my.getResult().get(2).getTitle()));
                            ii_title_4.setVisibility(View.GONE);

                            break;
                        case 4:
                            content_1.setText(Html.fromHtml(jsonModel_my.getResult().get(0).getContent()));
                            title_1.setText(Html.fromHtml(jsonModel_my.getResult().get(0).getTitle()));

                            content_2.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getContent()));
                            title_2.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getTitle()));

                            content_3.setText(Html.fromHtml(jsonModel_my.getResult().get(2).getContent()));
                            title_3.setText(Html.fromHtml(jsonModel_my.getResult().get(2).getTitle()));

                            content_4.setText(Html.fromHtml(jsonModel_my.getResult().get(len - 1).getContent()));
                            title_4.setText(Html.fromHtml(jsonModel_my.getResult().get(len - 1).getTitle()));
                            break;


                    }

                }
            }

            @Override
            public void onFailure(HttpException error, String msg) {
                ToastUtils.showShort(getApplicationContext(), "网络异常！");
            }
        });

    }
    
    private void initview() {
        initTopBar("联系我们");
        content_1 = (TextView)findViewById(R.id.content_1);
        title_1 = (TextView)findViewById(R.id.title_1);
        title_2 = (TextView)findViewById(R.id.title_2);
        content_2 = (TextView)findViewById(R.id.content_2);
        title_3 = (TextView)findViewById(R.id.title_3);
        content_3 = (TextView)findViewById(R.id.content_3);
        title_4 = (TextView)findViewById(R.id.title_4);
        content_4 = (TextView)findViewById(R.id.content_4);
        ii_title_1 = (LinearLayout) findViewById(R.id.ii_title_1);
        ii_title_2 = (LinearLayout) findViewById(R.id.ii_title_2);
        ii_title_3 = (LinearLayout) findViewById(R.id.ii_title_3);
        ii_title_4 = (LinearLayout) findViewById(R.id.ii_title_4);
        content_2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.content_2:
                Intent teleintent=new Intent(Intent.ACTION_DIAL);
                teleintent.setData(Uri.parse("tel:059183978755"));
                startActivity(teleintent);
                break;
        }
    }
}
